home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / netmail / wsomr120.zip / WS.DAT / TELIX.SLT < prev    next >
Text File  |  1996-04-24  |  4KB  |  188 lines

  1.  
  2. // =====================================================
  3. //    Telix Script for down/uploading of Internet mails
  4. //    By Frank Wang
  5. // =====================================================
  6.  
  7. // -- Replace following entries with yours - //
  8.  
  9. str dial_array[]  = "1 2 3 4 5";            // Entries in the directory
  10. str login_name[]  = "wang";                 // login name
  11. str password[]    = "######";               // your password
  12. str host_prompt[] = "durian.usc.edu.ph>";   // change this if your host is diff
  13. str in_file[]     = "inet.001";             // incoming mail
  14. str out_file[]    = "inet.txt";             // outgoing mail
  15. str log_file[]    = "inet.log";              // log file
  16.  
  17. // following two entries almost the same in the Internet
  18.  
  19. str login_pmt[] = "login:";
  20. str pswrd_pmt[] = "Password:";
  21.  
  22. // a possible change is in connect() function
  23.  
  24. // **** End of parameter area *** //
  25.  
  26. int max_try     = 99;
  27. int nstart      = 0;
  28. int nattemp_sec = 0;
  29. int nonline     = 0;
  30.  
  31. str log_str[80];
  32. str upload_file[80];
  33.  
  34. main()
  35. {
  36.   int ret, is_upload, t;
  37.   nstart = curtime();
  38.   copystr( _up_dir, upload_file, 0, strlen(_up_dir) );
  39.   strcat( upload_file, out_file );
  40.   hello();
  41.   is_upload = check_replies();
  42.   t = timer_start(0);
  43.   ret = connected();
  44.   nattemp_sec = timer_total(t);
  45.   if ( ret )
  46.   {
  47.     timer_restart(t, 0);
  48.     if ( is_upload )
  49.       upload_replies();
  50.     run_unix_script();
  51.     nonline = timer_total(t);
  52.     quit_proc();
  53.   }
  54.   else
  55.     prints( "Connection failed..." );
  56.  
  57.   update_log( ret );
  58.   status_wind( log_str, 50 );
  59.   exittelix( ret != 0, 1 );
  60. }
  61.  
  62. hello()
  63. {
  64.   clear_scr();
  65.   prints( "Connecting Internet..." );
  66. }
  67.  
  68. // Try to connect to Internet, return non zero if connected
  69. connected()
  70. {
  71.   int ret, cnt;
  72.   ret = dial( dial_array, max_try );
  73.   cnt = 0;
  74.   if ( ret )
  75.   {
  76.     while ( cnt < 20 )
  77.     {
  78.       if ( waitfor( login_pmt, 1 ) )
  79.         break;
  80.       cputc( 13 );
  81.       cnt = cnt + 1;
  82.     }
  83.     cput_line( login_name );
  84.     waitfor( pswrd_pmt );
  85.     cput_line( password );
  86. //    waitfor ( "Press Enter to continue..." );
  87. //    cputc( 13 );
  88.     waitfor ( host_prompt );
  89.   }
  90.   return ret;
  91. }
  92.  
  93. // Running xpost(Unix script) in Internet
  94.  
  95. run_unix_script()
  96. {
  97.   cputs( "sh wpost " );
  98.   cputs( in_file );
  99.   cputs( " " );
  100.   cputs( out_file );
  101.   cputc( 13 );
  102.   waitfor ( "wpost done", 60*10 );
  103. }
  104.  
  105. quit_proc()
  106. {
  107.   cput_line ( "quit" );
  108.   if ( waitfor( "login:", 20 ) )
  109.     hangup();
  110.   else
  111.     prints( "carrier probably lost by this time, safe to quit" );
  112. }
  113.  
  114. check_replies()
  115. {
  116.   int ret = 0;
  117.   str buf[20];
  118.  
  119.   if ( filefind(upload_file, 0, buf ) )
  120.   {
  121.     printsc( "<< Outgoing mail found " );
  122.     printsc( buf );
  123.     printsc( " size " );
  124.     printn( filesize( "" ) );
  125.     prints( " >>" );
  126.     ret = 1;
  127.   }
  128.   else
  129.     prints( "<< No outgoing mail found >> " );
  130.   return ret;
  131. }
  132.  
  133. upload_replies()
  134. {
  135.   str buf[16];
  136.   if ( filefind(upload_file, 0, buf) )
  137.   {
  138.     cputs( "rm " );
  139.     cputs( buf );
  140.     cputc( 13 );
  141.     cputs( "rz " );
  142.     cputs( buf );
  143.     cputc( 13 );
  144.  
  145.     send( 'Z', upload_file );
  146.     fdelete( upload_file );
  147.   }
  148. }
  149.  
  150. cput_line( str m )
  151. {
  152.   cputs( m );
  153.   cputc( 13 );
  154. }
  155.  
  156. update_log( int is_connected )
  157. {
  158.   int f;
  159.   str temp[64];
  160.  
  161.   date( nstart, temp );
  162.  
  163.   strcat( log_str, temp );
  164.   strcat( log_str, " " );
  165.  
  166.   time( nstart, temp );
  167.   strcat( log_str, temp );
  168.   strcat( log_str, " Connected:" );
  169.   if ( is_connected )
  170.     strcat( log_str, " OK" );
  171.   else
  172.     strcat( log_str, " NO" );
  173.   strcat( log_str, temp );
  174.   strcat( log_str, " Sec:" );
  175.   itos( nattemp_sec/10, temp );
  176.   strcat( log_str, temp );
  177.   strcat( log_str, " online time:" );
  178.   itos( nonline/10, temp );
  179.   strcat( log_str, temp );
  180.  
  181.   f = fopen( log_file, "a" );
  182.   fputs( log_str, f );
  183.   fputc( 0x0d, f );
  184.   fputc( 0x0a, f );
  185.   fclose(f);
  186. }
  187.  
  188.